package com.example.newproject_overseas.components


import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.newproject_overseas.R
import com.example.newproject_overseas.ui.theme.BaseElementComposeTheme
import kotlinx.coroutines.launch

@Composable
fun BottomInputBar(onInputListener:(String)->Unit) {
    var inputText by remember { mutableStateOf("") }

    Row(
        modifier = Modifier
            .shadow(4.dp, shape = RoundedCornerShape(8.dp))
            .fillMaxWidth()
            .background(BaseElementComposeTheme.colors.background)
            .padding(start = 10.dp, end = 10.dp, top = 5.dp, bottom = 20.dp)
            .clip(RoundedCornerShape(4.dp)),
        verticalAlignment = Alignment.CenterVertically
    )
    {
//        Icon(
//            painter = painterResource(id = R.drawable.ic_voice),
//            contentDescription = "语音",
//            tint = BaseElementComposeTheme.colors.icon,
//            modifier = Modifier.size(28.dp)
//        )

        Spacer(modifier = Modifier.width(5.dp))

        BasicTextField(
            value = inputText,
            onValueChange = { inputText = it },
            modifier = Modifier
                .background(BaseElementComposeTheme.colors.textFieldBackground)
                .weight(1f)
                .height(40.dp)
                .padding(start = 5.dp, end = 5.dp, top = 10.dp),
            textStyle = TextStyle(textAlign = TextAlign.Start, fontSize = 14.sp),
            keyboardActions = KeyboardActions (
                onSend = {
                    onInputListener(inputText)
                    inputText = ""
                }
            ),
            keyboardOptions = KeyboardOptions(
                keyboardType = KeyboardType.Text,
                imeAction = ImeAction.Send
            )
        )
        Row(modifier = Modifier) {
            Button(
                onClick = {
                    onInputListener(inputText)
                    inputText = ""
                    Log.e(inputText, "点击获取输入值: ", )
                },
                modifier = Modifier
                    .padding(top = 13.dp, bottom = 13.dp, end = 20.dp, start = 24.dp),
                colors = ButtonDefaults.buttonColors(Color(0xFFE0E1E2)),
                shape = RoundedCornerShape(4.5.dp)
            ) {
                Text(
                    text = "Send",
                    color = Color(0xFFFFCC00),
                    fontSize = 20.sp,
                    fontWeight = FontWeight.Bold
                )
            }
        }
//        Spacer(modifier = Modifier.width(5.dp))

//        Icon(
//            painter = painterResource(id = R.drawable.ic_stickers),
//            contentDescription = "表情",
//            tint = BaseElementComposeTheme.colors.icon,
//            modifier = Modifier.size(28.dp)
//        )

//        Spacer(modifier = Modifier.width(10.dp))

//        Icon(
//            painter = painterResource(id = R.drawable.ic_add),
//            contentDescription = "添加",
//            tint = BaseElementComposeTheme.colors.icon,
//            modifier = Modifier.size(28.dp)
//        )

    }
}

@Preview
@Composable
fun BottomInputBarPreview() {
    BottomInputBar(onInputListener = { inputText ->
        // 处理输入文本的逻辑，例如打印或其他操作
        Log.e(inputText, "BottomInputBarPreview: ", )
    })
}

